package com.css.fxfzypg.modules.hypergraph.service.impl;

import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.css.fxfzypg.base.attachment.entity.AttachmentInfoEntity;
import com.css.fxfzypg.base.attachment.service.AttachmentInfoService;
import com.css.fxfzypg.base.dict.repository.DictItemRepository;
import com.css.fxfzypg.base.dict.repository.entity.DictItemEntity;
import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.modules.downloadLegend.entity.TemplateEntity;
import com.css.fxfzypg.modules.hypergraph.service.HypergraphService;
import com.css.fxfzypg.util.PlatformObjectUtils;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.core.env.Environment;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.*;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.io.*;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: fxfzdzzh
 * @Author: lhl
 * @CreateDate: 2023/6/5 14:23
 * 超图
 */
@Service
public class HypergraphServiceImpl implements HypergraphService {

    @Value("${hypergraph.iServerHttp}")
    String iServerHttp;
    @Value("${hypergraph.userName}")
    String userName;
    @Value("${hypergraph.password}")
    String password;
    @Resource
    private Environment environment;

    //    @Resource
//    RestTemplate restTemplate;
    RestTemplate restTemplate = getRestTemplate();

    @Value("${hypergraph.filePath}")
    String filePath;
    @Value("${hypergraph.mapsPath}")
    String mapsPath;

    @Resource
    DictItemRepository dictItemRepository;
    @Resource
    private AttachmentInfoService attachmentInfoService;

    /**
     * 调度器使用的RestTemplate，超时6000s
     *
     * @return
     */
    @Override
    public RestTemplate getRestTemplate() {
        RestTemplate restTemplate = new RestTemplateBuilder()
                .setConnectTimeout(Duration.ofSeconds(6000))
                .setReadTimeout(Duration.ofSeconds(6000))
                .build();
        //解决中文乱码
        List<HttpMessageConverter<?>> msgConv = restTemplate.getMessageConverters();
        if (msgConv != null && !msgConv.isEmpty()) {
            for (int i = 0; i < msgConv.size(); i++) {
                if (msgConv.get(i).getClass().equals(StringHttpMessageConverter.class)) {
                    msgConv.set(i, new StringHttpMessageConverter(StandardCharsets.UTF_8));
                }
            }
        }
        return restTemplate;
    }

    /**
     * @param map layerName:
     *            type://类型
     *            tif//高程
     *            filePath:
     *            slopeTif//坡度
     *            teraName:
     *            filePath:
     *            aspectTif//坡向
     *            teraName:
     *            filePath:
     *            clipTif//栅格裁剪文件
     *            geomText:
     *            resultLayerName:
     *            filePath:
     *            countTif//栅格自定义计算发布
     *            countString:
     *            countTif2//栅格自定义计算
     *            countString:
     *            countMapsTif//栅格自定义计算图层模板
     *            mapsName:
     *            countString:
     *            maxMinTif//栅格基本统计-获取最大最小值
     *            vectorTif-5//ypg系统的矢量转栅格的数据集 vectorTif-4//与基础数据的矢量转栅格的数据集  vectorTif-3//与dzzh系统的矢量转栅格的数据集
     *            clipLayerName:
     *            fieldName:
     *            sqlFilter:
     *            sqlFilterClip:
     *            exportTif//tif发布超图服务工具--创建任务（导出tif文件）
     *            demHslCount//tif发布超图服务工具--创建任务（DEM高程计算汇水量a）
     *            batchDelTif //tif发布超图服务工具--批量删除栅格数据集
     *            WorkspaceReload//刷新指定超图工作空间数据源数据集
     *            datasource:
     *            dataset:
     *            demCdlbCount//tif发布超图服务工具--创建任务（DEM高程计算场地类别）
     * @return
     */
    @Override
    public RestResponse getServerToken(Map<String, Object> map) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/security/tokens.rjson";
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            jsonObject.put("userName", userName);
            jsonObject.put("password", password);
            jsonObject.put("clientType", "NONE");//查询数量
            jsonObject.put("expiration", 120);//申请令牌的有效期，从发布令牌的时间开始计算，单位为分钟
            //System.out.println(jsonObject);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<String> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, String.class);
            String token = exchange.getBody();
            // result.put("result", exchange.getBody());

            String type = (String) map.get("type");
            String layerName = (String) map.get("layerName");
            if (type.equals("tif")) {
                String filePath = (String) map.get("filePath");
                //tif发布超图服务工具--创建任务（tif发布）
                restResponse = tifMapLayerToolJobPost(layerName, filePath, token);
            } else if (type.equals("demTif")) {
                String filePath = (String) map.get("filePath");
                //tif发布超图服务工具--创建任务（tif发布高程ypg）
                restResponse = tifMapLayerToolJobPostDEM(layerName, filePath, token);
            } else if (type.equals("importSlopeTif")) {
                String filePath = (String) map.get("filePath");
                //tif发布超图服务工具--创建任务（导入坡度文件发布）
                restResponse = tifMapLayerToolJobPostPd(layerName, filePath, token);
            } else if (type.equals("importAspectTif")) {
                String filePath = (String) map.get("filePath");
                //tif发布超图服务工具--创建任务（导入坡向文件发布）
                restResponse = tifMapLayerToolJobPostPx(layerName, filePath, token);
            } else if (type.equals("slopeTif")) {
                String teraName = (String) map.get("teraName");
                String filePath = (String) map.get("filePath");
                //tif发布超图服务工具--创建任务（生成坡度）
                restResponse = tifMapLayerToolJobPost2(teraName, layerName, filePath, token);
            } else if (type.equals("aspectTif")) {
                String teraName = (String) map.get("teraName");
                String filePath = (String) map.get("filePath");
                //tif发布超图服务工具--创建任务（生成坡向）
                restResponse = tifMapLayerToolJobPost3(teraName, layerName, filePath, token);
            } else if (type.equals("clipTif")) {
                // String filePath = (String) map.get("filePath");
                String resultLayerName = (String) map.get("resultLayerName");//裁剪结果数据集
                if (PlatformObjectUtils.isEmpty(resultLayerName)) {
                    String currTime = System.currentTimeMillis() + "";
//                    resultLayerName = layerName + "_裁剪_" + currTime;//裁剪结果数据集
                    resultLayerName = "temp_裁剪_" + currTime;//裁剪结果数据集
                }
                String geomText = (String) map.get("geomText");
//                if (geomText == null) {
//                    geomText = "MULTIPOLYGON(((100 30,103 30,103 31,102 31,101 30.5,100 30)))";
//                }
                //tif发布超图服务工具--创建任务（栅格裁剪文件发布）
                restResponse = tifMapLayerToolJobPost4("demtif", layerName, resultLayerName, filePath, exchange.getBody(), geomText);
            } else if (type.equals("clipTif-dzzhTifFile")) {
                // String filePath = (String) map.get("filePath");
                String resultLayerName = (String) map.get("resultLayerName");//裁剪结果数据集
                if (PlatformObjectUtils.isEmpty(resultLayerName)) {
                    String currTime = System.currentTimeMillis() + "";
//                    resultLayerName = layerName + "_裁剪_" + currTime;//裁剪结果数据集
                    resultLayerName = "temp_裁剪_" + currTime;//裁剪结果数据集
                }
                String geomText = (String) map.get("geomText");
//                if (geomText == null) {
//                    geomText = "MULTIPOLYGON(((100 30,103 30,103 31,102 31,101 30.5,100 30)))";
//                }
                //tif发布超图服务工具--创建任务（栅格裁剪文件发布）
                restResponse = tifMapLayerToolJobPost4("dzzhTifFile", layerName, resultLayerName, filePath, exchange.getBody(), geomText);
            } else if (type.equals("clipTif2")) {
                // String filePath = (String) map.get("filePath");
                String resultLayerName = (String) map.get("resultLayerName");//裁剪结果数据集
                if (PlatformObjectUtils.isEmpty(resultLayerName)) {
                    String currTime = System.currentTimeMillis() + "";
//                    resultLayerName = layerName + "_裁剪_" + currTime;//裁剪结果数据集
                    resultLayerName = "temp_裁剪_" + currTime;//裁剪结果数据集
                }
                //任务范围的经纬度数据
                String geomText = (String) map.get("geomText");
//                if (geomText == null) {
//                    geomText = "MULTIPOLYGON(((100 30,103 30,103 31,102 31,101 30.5,100 30)))";
//                }
                //tif发布超图服务工具--创建任务（栅格裁剪）
                restResponse = tifMapLayerToolJobPost4_1("demtif", layerName, resultLayerName, geomText, token);
            } else if (type.equals("clipTif2-dzzhTifFile")) {
                // String filePath = (String) map.get("filePath");
                String resultLayerName = (String) map.get("resultLayerName");//裁剪结果数据集
                if (PlatformObjectUtils.isEmpty(resultLayerName)) {
                    String currTime = System.currentTimeMillis() + "";
//                    resultLayerName = layerName + "_裁剪_" + currTime;//裁剪结果数据集
                    resultLayerName = "temp_裁剪_" + currTime;//裁剪结果数据集
                }
                //任务范围的经纬度数据
                String geomText = (String) map.get("geomText");
//                if (geomText == null) {
//                    geomText = "MULTIPOLYGON(((100 30,103 30,103 31,102 31,101 30.5,100 30)))";
//                }
                //tif发布超图服务工具--创建任务（栅格裁剪）
                restResponse = tifMapLayerToolJobPost4_1("dzzhTifFile", layerName, resultLayerName, geomText, token);
            } else if (type.equals("countTif")) {
                // String countString = "Con([demtif.test_计算_3] < 0.01, 10, Con([demtif.test_计算_3] < 0.03, 20, Con([demtif" +
                //         ".test_计算_3] < 0.09, 30, Con([demtif.test_计算_3] < 0.27, 40, 50))))";
                String countString = (String) map.get("countString");
                //tif发布超图服务工具--创建任务（栅格计算发布）
                restResponse = tifMapLayerToolJobPost5(layerName, countString, token);
            } else if (type.equals("countMapsTif")) {
                // String countString = "Con([demtif.test_计算_3] < 0.01, 10, Con([demtif.test_计算_3] < 0.03, 20, Con([demtif" +
                //         ".test_计算_3] < 0.09, 30, Con([demtif.test_计算_3] < 0.27, 40, 50))))";
                String countString = (String) map.get("countString");
                String mapsName = (String) map.get("mapsName");
                //tif发布超图服务工具--创建任务（栅格计算发布图层模板）
                restResponse = tifMapLayerToolJobPost5_2(layerName, mapsName, countString, token);
            } else if (type.equals("countTif2")) {
                // String countString = "Con([demtif.test_计算_3] < 0.01, 10, Con([demtif.test_计算_3] < 0.03, 20, Con([demtif" +
                //         ".test_计算_3] < 0.09, 30, Con([demtif.test_计算_3] < 0.27, 40, 50))))";
                String countString = (String) map.get("countString");
                //tif发布超图服务工具--创建任务（栅格计算）
                restResponse = tifMapLayerToolJobPost5_3(layerName, countString, token);
            } else if (type.equals("maxMinTif")) {
                // layerName = "test_计算_3";
                //tif发布超图服务工具--同步执行处理自动化工具（栅格基本统计-获取最大最小值）
                restResponse = tifMapLayerToolJobGet1(layerName, token);
            } else if (type.contains("vectorTif")) {
                // layerName = "dzzh_task";//矢量转栅格的数据集
                String clipLayerName = (String) map.get("clipLayerName");
                //边界数据集
//                String timeStamp = System.currentTimeMillis() + "";//时间戳，用于数据集名称后缀，防止重名
                String timeStamp = (String) map.get("currTime");//时间戳，用于数据集名称后缀，防止重名
//                String resultLayerName = layerName + "_矢量转栅格_" + timeStamp;//裁剪结果数据集
                String resultLayerName = "temp_" + layerName + "_栅格_" + timeStamp;//裁剪结果数据集
                // String resultFilePath = "E:/MapData/tif/tif/" + resultLayerName + ".tif";
                //裁剪结果数据集保存的路径
                String fieldName = (String) map.get("fieldName");
                //用于生成栅格值的矢量数据的字段，默认用超图自身的字段SmUserID值为0
                //矢量数据
                String datasetName = layerName;//用于转换栅格的矢量数据集名称
                String tempDatasetName = "temp_" + datasetName + "_" + timeStamp;//矢量过滤临时结果数据集名称
                //过滤查询数据的表达式，即只保留符合sql条件的数据
                String sqlFilter = (String) map.get("sqlFilter");

                //边界裁剪
                String datasetNameClip = clipLayerName;//用于转换栅格的边界矢量数据集名称
                String tempDatasetNameClip = "temp_" + datasetNameClip + "_clip_" + timeStamp;//边界矢量过滤临时结果数据集名称
                //边界过滤查询数据的表达式，即只保留符合sql条件的数据
                String sqlFilterClip = (String) map.get("sqlFilterClip");
                /*//tif发布超图服务工具--创建任务（矢量过滤转换栅格发布）
                restResponse = tifMapLayerToolJobPost6(datasetName,
                        resultLayerName, fieldName,
                        tempDatasetName, sqlFilter,
                        tempDatasetNameClip, datasetNameClip, sqlFilterClip,
                        exchange.getBody(), type);*/

                //fxfzypg、fxfzdzzh、datacenter系统矢量过滤查询到ypgTifCount
                //tif发布超图服务工具--矢量过滤查询
                String queryType = "fxfzypg";//查询类型：fxfzypg、fxfzdzzh、datacenter
                if ("vectorTif-3".equals(type)) {//dzzh系统数据，边界ypg系统任务
                    queryType = "fxfzdzzh";
                } else if ("vectorTif-4".equals(type)) {//datacenter系统数据，边界ypg系统任务
                    queryType = "datacenter";
                } else if ("vectorTif-5".equals(type)) {//ypg系统数据，边界ypg系统任务
                    queryType = "fxfzypg";
                }
                //String 矢量数据集名称，String_1 结果数据集名，String_2 SQL查询表达式
                restResponse = tifMapLayerToolJobPost13(layerName, tempDatasetName, sqlFilter, queryType, token);
                if (restResponse.getCode() != 200) {
                    return restResponse;
                }
                //ypgTifCount矢量栅格化
                //tif发布超图服务工具--矢量转换栅格ypg
                //String 矢量数据集名称 String_1 边界矢量数据集名称 String_2 字段名称 String_3 结果数据集名称
                restResponse = tifMapLayerToolJobPost24(tempDatasetName, clipLayerName, fieldName, resultLayerName, token);
            } else if (type.equals("exportTif")) {
                //tif发布超图服务工具--创建任务（导出tif文件）
                restResponse = tifMapLayerToolJobPost7(layerName, token);
            } else if (type == "demHslCount") {
                //tif发布超图服务工具--创建任务（DEM高程计算汇水量a）
                String timeStamp = System.currentTimeMillis() + "";//时间戳，用于数据集名称后缀，防止重名
                restResponse = tifMapLayerToolJobPost8(layerName, timeStamp, token);
            } else if (type == "demCdlbCount") {
                //tif发布超图服务工具--创建任务（DEM高程计算场地类别）
                String timeStamp = System.currentTimeMillis() + "";//时间戳，用于数据集名称后缀，防止重名
                String flag = (String) map.get("flag");
                String sql = "";
                String layerName2 = "temp_百分比_坡度_" + timeStamp;
                //通过坡度百分比计算场地类别sql
                if ("1".equals(flag)) {
                    //活动构造区
                    sql = "Con([demtif." + layerName2 + "]==-9999,-9999," +
                            "Con([demtif." + layerName2 + "]<0.01,0," +
                            "Con([demtif." + layerName2 + "]<1.8,0.751," +
                            "Con([demtif." + layerName2 + "]<13.8,0.178,0.070))))";
                } else if ("2".equals(flag)) {
                    //稳定大陆区
                    sql = "Con([demtif." + layerName2 + "]==-9999,-9999," +
                            "Con([demtif." + layerName2 + "]<0.002,0," +
                            "Con([demtif." + layerName2 + "]<0.72,0.751," +
                            "Con([demtif." + layerName2 + "]<2.5,0.178,0.070))))";
                }
                restResponse = tifMapLayerToolJobPost9(layerName, timeStamp, exchange.getBody(), sql, flag);
            } else if (type.equals("reclassify")) {
                //tif发布超图服务工具--创建任务（重分类自然分割法发布）
                String timeStamp = System.currentTimeMillis() + "";//时间戳，用于数据集名称后缀，防止重名
                restResponse = tifMapLayerToolJobPost10(layerName, timeStamp, token);
            } else if (type.equals("batchDelTif")) {
                //tif发布超图服务工具--批量删除栅格数据集
                restResponse = tifMapLayerToolJobPost11(layerName, token);
            } else if (type.equals("gridFusion")) {
                //tif发布超图服务工具--全部栅格值矢量化融合
                String resultLayerName1 = (String) map.get("resultLayerName1");//矢量化结果数据集名
                String resultLayerName2 = (String) map.get("resultLayerName2");//结果数据集名
                //String 栅格数据集名称；String_1  矢量化结果数据集名；String_2 结果数据集名
                restResponse = tifMapLayerToolJobPost12(layerName, resultLayerName1, resultLayerName2,
                        token);
            } else if (type.equals("ypgVectorQuery")) {
                //tif发布超图服务工具--ypg矢量过滤查询
                String resultLayerName = (String) map.get("resultLayerName");//结果数据集名
                String sqlFilter = (String) map.get("sqlFilter");//SQL查询表达式
                String queryType = (String) map.get("queryType");//查询类型：fxfzypg、fxfzdzzh、datacenter、ypgTifCount
                //String 矢量数据集名称，String_1 结果数据集名，String_2 SQL查询表达式
                restResponse = tifMapLayerToolJobPost13(layerName, resultLayerName, sqlFilter, queryType, token);
            } else if (type.equals("ypgIntersects")) {
                //tif发布超图服务工具--ypg矢量求交
                String clipLayerName = (String) map.get("clipLayerName");//叠加数据集名
                String resultLayerName = (String) map.get("resultLayerName");//结果数据集名
                //String 源矢量数据集名，String_1 叠加数据集名，String_2 结果数据集名
                restResponse = tifMapLayerToolJobPost14(layerName, clipLayerName, resultLayerName,
                        token);
            } else if (type.equals("ypgCountTif")) {
                //tif发布超图服务工具--dem栅格计算ypg
                String countString = (String) map.get("countString");
                //String 算术表达式，String_1 栅格计算结果数据集名
//                restResponse = tifMapLayerToolJobPost15(countString, layerName,token);
                //tif发布超图服务工具--创建任务（栅格计算）
                restResponse = tifMapLayerToolJobPost5_3(layerName, countString, token);
                if (restResponse.getCode() != 200) {
                    return restResponse;
                }
                //从demtif复制数据集到ypgTifCount
                //tif发布超图服务工具--dem复制数据集ypg
                //String 数据集名称
                restResponse = tifMapLayerToolJobPost22(layerName, token);
            } else if (type.equals("ypgCountTif-1")) {
                //tif发布超图服务工具--栅格计算ypg
                String countString = (String) map.get("countString");
                //String 算术表达式，String_1 栅格计算结果数据集名
                restResponse = tifMapLayerToolJobPost15_1(countString, layerName, token);
            } else if (type.equals("countMapTifAllVector")) {
                //tif发布超图服务工具--全部栅格矢量化发布图层模板
                String resultLayerName = (String) map.get("resultLayerName");//结果数据集名
                String mapsName = (String) map.get("mapsName");//图层模板文件名
                //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化结果数据集名，String_3 图层模板文件路径
                restResponse = tifMapLayerToolJobPost16(layerName, resultLayerName, mapsName, token);
            } else if (type.equals("countTifAllVector")) {
                //tif发布超图服务工具--全部栅格矢量化
                String resultLayerName = (String) map.get("resultLayerName");//结果数据集名
                //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化结果数据集名
                restResponse = tifMapLayerToolJobPost16_1(layerName, resultLayerName, token);
            } else if (type.equals("countMapTifValueBuffer")) {
                //tif发布超图服务工具--指定栅格矢量化缓冲区发布图层模板
                String resultLayerName = (String) map.get("resultLayerName");//矢量化数据集名
                String resultLayerName2 = (String) map.get("resultLayerName2");//结果数据集名
                String mapsName = (String) map.get("mapsName");//图层模板文件名
                String gridvalue = (String) map.get("gridvalue");//指定栅格值
                String bufferMeter = (String) map.get("bufferMeter");//缓冲区半径米
                //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化数据集名，String_3 结果数据集名，String_4 图层模板文件路径，Long 指定栅格值，Double 缓冲区半径米
                restResponse = tifMapLayerToolJobPost17(layerName, resultLayerName, resultLayerName2, mapsName, gridvalue, bufferMeter, token);
            } else if (type.equals("countTifValueBuffer")) {
                //tif发布超图服务工具--指定栅格矢量化缓冲区
                String resultLayerName = (String) map.get("resultLayerName");//矢量化数据集名
                String resultLayerName2 = (String) map.get("resultLayerName2");//结果数据集名
                String gridvalue = (String) map.get("gridvalue");//指定栅格值
                String bufferMeter = (String) map.get("bufferMeter");//缓冲区半径米
                //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化数据集名，String_3 结果数据集名，Long 指定栅格值，Double 缓冲区半径米
//                restResponse = tifMapLayerToolJobPost17_1(layerName, resultLayerName, resultLayerName2, gridvalue, bufferMeter, token);

                //tif发布超图服务工具--ypg矢量过滤查询
                String sqlFilter = "GRIDVALUE=" + gridvalue;
                //String 矢量数据集名称，String_1 结果数据集名，String_2 SQL查询表达式
                restResponse = tifMapLayerToolJobPost13(layerName, resultLayerName, sqlFilter, "ypgTifCount", token);
                if (restResponse.getCode() != 200) {
                    return restResponse;
                }
                //tif发布超图服务工具--ypg矢量数据创建缓冲区
                //String 矢量数据集名称 String_1 边界矢量数据集名称 String_2 结果数据集名称
                restResponse = tifMapLayerToolJobPost26(resultLayerName, resultLayerName2, bufferMeter, token);
            } else if (type.equals("batchDelByLayerType")) {
                String layerType = (String) map.get("layerType");//图层类型（栅格、面）
                //tif发布超图服务工具--根据名称、类型批量删除数据集
                restResponse = tifMapLayerToolJobPost18(layerName, layerType, token);
            } else if (type.equals("ypgVectorClipMap")) {
                //tif发布超图服务工具--ypg矢量裁剪发布图层模板
                String clipLayerName = (String) map.get("clipLayerName");//裁剪范围数据集名
                String resultLayerName = (String) map.get("resultLayerName");//结果数据集名
                String mapsName = (String) map.get("mapsName");//图层模板文件名
                //String 矢量数据集名称，String_1 结果数据集名，String_2 SQL查询表达式
                restResponse = tifMapLayerToolJobPost19(layerName, clipLayerName, resultLayerName, mapsName, token);
            } else if (type.equals("ypgVectorClipMapCopy")) {
                //tif发布超图服务工具--ypg矢量裁剪发布图层模板复制数据集
                String clipLayerName = (String) map.get("clipLayerName");//裁剪范围数据集名
                String resultLayerName = (String) map.get("resultLayerName");//结果数据集名
                String mapsName = (String) map.get("mapsName");//图层模板文件名
                //String 矢量数据集名称，String_1 结果数据集名，String_2 SQL查询表达式
                restResponse = tifMapLayerToolJobPost20(layerName, clipLayerName, resultLayerName, mapsName, token);
            } else if (type.equals("ypgMapsLayer")) {
                //tif发布超图服务工具--ypg计算数据自动制图发布图层模板
                String mapsName = (String) map.get("mapsName");//图层模板文件名
                //String 结果数据集名，String_1 图层模板文件名
                restResponse = tifMapLayerToolJobPost21(layerName, mapsName, token);
            } else if (type.equals("ypgCopyTif")) {//demtif复制数据集到ypgTifCount
                //tif发布超图服务工具--dem复制数据集ypg
                //String 数据集名称
                restResponse = tifMapLayerToolJobPost22(layerName, token);
            } else if (type.equals("ypgCountCopyVector")) {//ypgTifCount复制数据集到fxfzypg
                //tif发布超图服务工具--ypg复制数据集
                //String 数据集名称
                restResponse = tifMapLayerToolJobPost23(layerName, token);
            } else if (type.equals("ypgCountVectorTif")) {//ypgTifCount矢量栅格化
                //tif发布超图服务工具--矢量转换栅格ypg
                String clipLayerName = (String) map.get("clipLayerName");//裁剪范围数据集名
                String fieldName = (String) map.get("fieldName");//字段名称
                String resultLayerName = (String) map.get("resultLayerName");//结果数据集名
                //String 矢量数据集名称 String_1 边界矢量数据集名称 String_2 字段名称 String_3 结果数据集名称
                restResponse = tifMapLayerToolJobPost24(layerName, clipLayerName, fieldName, resultLayerName, token);
            } else if (type.equals("ypgClipTif")) {
                //tif发布超图服务工具--ypg矢量面裁剪栅格
                String clipLayerName = (String) map.get("clipLayerName");//裁剪范围数据集名
                String resultLayerName = (String) map.get("resultLayerName");//结果数据集名
                //String 矢量数据集名称 String_1 边界矢量数据集名称 String_2 结果数据集名称
                restResponse = tifMapLayerToolJobPost25(layerName, clipLayerName, resultLayerName, token);
            } else if (type.equals("ypgVectorBuffer")) {
                //tif发布超图服务工具--ypg矢量数据创建缓冲区
                String resultLayerName = (String) map.get("resultLayerName");//结果数据集名
                String bufferMeter = (String) map.get("bufferMeter");//缓冲区半径米
                //String 矢量数据集名称 String_1 边界矢量数据集名称 String_2 结果数据集名称
                restResponse = tifMapLayerToolJobPost26(layerName, resultLayerName, bufferMeter, token);
            } else if (type.equals("ypgVectorArea")) {
                //tif发布超图服务工具--矢量查询计算面积ypg
                String sqlFilter = (String) map.get("sqlFilter");//查询过滤条件
                //tif发布超图服务工具--同步执行处理自动化工具（矢量查询计算面积ypg）
                restResponse = tifMapLayerToolJobGet2(layerName, sqlFilter, token);
            } else if (type.equals("getWebprintingLayoutsList")) {//获取Web打印出图模板列表
                //获取Web打印出图模板列表
                restResponse = supermapGetTemplateEntityList(map, token);
            } else if (type.equals("uploadTemplateFile")) {//上传模板文件到超图模板目录
                String format = (String) map.get("format");//版式  0横板  1竖版  2无 3横版带简介
                //上传模板文件到超图模板目录
                restResponse = supermapPostTemplateFile(map, format, token);
            } else if (type.equals("WorkspaceReload")) {
                String datasource = (String) map.get("datasource");//数据源
                String dataset = (String) map.get("dataset");//数据集
                //查询字典--超图数据源工作空间文件路径
                DictItemEntity dte = dictItemRepository.findOneByDictItemCodeAndDictId(datasource, "12");
                String smwuUrl = dte.getDictItemName();//工作空间文件路径
                //刷新指定超图工作空间数据源数据集
                restResponse = mapLayerWorkspaceReload(smwuUrl, datasource, dataset, token);
            } else if (type.equals("token")) {//获取超图服务token
                restResponse = RestResponse.succeed(token);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //tif发布超图服务工具--创建任务（生成高程）
    private RestResponse tifMapLayerToolJobPost(String layerName, String filePath, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:tif发布/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            if (PlatformObjectUtils.isEmpty(filePath)) {
                parameter.put("String", filePath + layerName + ".tif");//tif文件路径
            } else {
                parameter.put("String", filePath);//栅格裁剪结果文件路径
            }
            parameter.put("String_1", layerName);//栅格数据集名称
            parameter.put("String_2", layerName);//栅格图层名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //tif发布超图服务工具--创建任务（tif发布高程ypg）
    private RestResponse tifMapLayerToolJobPostDEM(String layerName, String filePath, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:tif发布高程ypg/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            if (PlatformObjectUtils.isEmpty(filePath)) {
                parameter.put("String", filePath + layerName + ".tif");//tif文件路径
            } else {
                parameter.put("String", filePath);//栅格裁剪结果文件路径
            }
            parameter.put("String_1", layerName);//栅格数据集名称
            parameter.put("String_2", layerName);//栅格图层名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //tif发布超图服务工具--创建任务（导入坡度）
    private RestResponse tifMapLayerToolJobPostPd(String layerName, String filePath, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:导入坡度文件发布/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            if (PlatformObjectUtils.isEmpty(filePath)) {
                parameter.put("String", filePath + layerName + ".tif");//tif文件路径
            } else {
                parameter.put("String", filePath);//栅格裁剪结果文件路径
            }
            parameter.put("String_1", layerName);//栅格数据集名称
            parameter.put("String_2", layerName);//栅格图层名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //tif发布超图服务工具--创建任务（导入坡向）
    private RestResponse tifMapLayerToolJobPostPx(String layerName, String filePath, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:导入坡向文件发布/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            if (PlatformObjectUtils.isEmpty(filePath)) {
                parameter.put("String", filePath + layerName + ".tif");//tif文件路径
            } else {
                parameter.put("String", filePath);//栅格裁剪结果文件路径
            }
            parameter.put("String_1", layerName);//栅格数据集名称
            parameter.put("String_2", layerName);//栅格图层名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //tif发布超图服务工具--创建任务（生成坡度）
    private RestResponse tifMapLayerToolJobPost2(String teraName, String layerName, String filePath, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:生成坡度/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", teraName);//高程数据集名称
            parameter.put("String_1", layerName);//坡度数据集名称
            if (PlatformObjectUtils.isEmpty(filePath)) {
                parameter.put("String_2", filePath + layerName + ".tif");
            } else {
                parameter.put("String_2", filePath);//栅格裁剪结果文件路径
            }
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //tif发布超图服务工具--创建任务（生成坡向）
    private RestResponse tifMapLayerToolJobPost3(String teraName, String layerName, String filePath, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:生成坡向/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", teraName);//高程数据集名称
            parameter.put("String_1", layerName);//坡向数据集名称
            if (PlatformObjectUtils.isEmpty(filePath)) {
                parameter.put("String_2", filePath + layerName + ".tif");
            } else {
                parameter.put("String_2", filePath);//栅格裁剪结果文件路径
            }
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //面wkt裁剪栅格文件发布（裁剪栅格数据集，然后导出文件并发布裁剪结果图层）
    private RestResponse tifMapLayerToolJobPost4(String type, String layerName, String resultLayerName, String filePath, String serverToken, String geomText) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:面wkt裁剪栅格文件发布/jobs?token=" + serverToken;
            if (type.equals("demtif")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:面wkt裁剪栅格文件发布/jobs?token=" + serverToken;
            } else if (type.equals("dzzhTifFile")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:面wkt裁剪栅格文件发布dzzhfile/jobs?token=" + serverToken;
            }
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("GeoRegion", geomText);//面几何对象wkt
            parameter.put("81d2403b-02b5-4735-978b-48724a006e82", layerName);//栅格数据集名称
            parameter.put("64df700f-7c1d-4ff0-8d74-2a5f8114e8e8", -9999);//栅格无值
            parameter.put("52868036-e093-4e1e-9662-db82d7e5b7ab", resultLayerName);//栅格裁剪结果数据集名称
            parameter.put("7cb39b22-8ee1-48d4-ba0c-9067576e1b10", filePath + resultLayerName + ".tif");//栅格裁剪结果文件路径

            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                restResponse.setData(filePath + resultLayerName + ".tif");
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //面wkt裁剪栅格（只裁剪栅格数据集，不导出文件，不发布裁剪结果图层）
    private RestResponse tifMapLayerToolJobPost4_1(String type, String layerName, String resultLayerName, String geomText, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg面wkt裁剪栅格/jobs?token=" + serverToken;
            if (type.equals("demtif")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg面wkt裁剪栅格dem/jobs?token=" + serverToken;
            } else if (type.equals("dzzhTifFile")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg面wkt裁剪栅格dzzhfile/jobs?token=" + serverToken;
            }
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("GeoRegion", geomText);//面几何对象wkt
            parameter.put("String", layerName);//栅格数据集名称
            parameter.put("String_1", resultLayerName);//结果数据集名称

            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                restResponse.setData(filePath + resultLayerName + ".tif");
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    private RestResponse tifMapLayerToolJobPost5(String resultLayerName, String countString, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:栅格计算发布/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", countString);//栅格计算表达式
            parameter.put("String_1", resultLayerName);//计算结果数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                restResponse.setData(filePath + resultLayerName + ".tif");
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    private RestResponse tifMapLayerToolJobPost5_2(String resultLayerName, String mapsName, String countString
            , String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:栅格计算发布图层模板/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", countString);//栅格计算表达式
            parameter.put("String_1", resultLayerName);//计算结果数据集名称
            parameter.put("String_2", mapsPath + mapsName);//图层模板
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                restResponse.setData(filePath + resultLayerName + ".tif");
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    private RestResponse tifMapLayerToolJobPost5_3(String resultLayerName, String countString, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:栅格计算/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", countString);//栅格计算表达式
            parameter.put("String_1", resultLayerName);//计算结果数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //tif发布超图服务工具--创建任务（矢量过滤转换栅格发布）
    private RestResponse tifMapLayerToolJobPost6(String datasetName,
                                                 String resultLayerName, String fieldName,
                                                 String tempDatasetName, String sqlFilter,
                                                 String tempDatasetNameClip, String datasetNameClip, String sqlFilterClip,
                                                 String serverToken, String type) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:矢量过滤转换栅格发布ypg/jobs?token=" + serverToken;
            if ("vectorTif-3".equals(type)) {//dzzh系统数据，边界ypg系统任务
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:矢量过滤转换栅格发布ypg/jobs?token=" + serverToken;
            } else if ("vectorTif-4".equals(type)) {//datacenter系统数据，边界ypg系统任务
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:矢量过滤转换栅格发布基础数据ypg/jobs?token=" + serverToken;
            } else if ("vectorTif-5".equals(type)) {//ypg系统数据，边界ypg系统任务
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg矢量过滤转换栅格发布/jobs?token=" + serverToken;
            }
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            String resultFilePath = filePath + resultLayerName + ".tif";
            Double size = 0.0008880937137850466;//单元格大小，即栅格分辨率，可通过读取原栅格数据的分辨率设置，需要将如8.880937137850466E-4的科学记数转成浮点数
            Double noDataValue = -9999d;//空白区域值，即设置无值
            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", resultLayerName);//结果数据集名称
            parameter.put("String_1", fieldName);//字段名称
            parameter.put("String_2", datasetName);//矢量数据集名称
            parameter.put("String_3", tempDatasetName);//目标数据集名称
            parameter.put("String_4", sqlFilter);//SQL过滤表达式
            parameter.put("String_5", datasetNameClip);//边界矢量数据集名称
            parameter.put("String_6", tempDatasetNameClip);//边界目标数据集名称
            parameter.put("String_7", sqlFilterClip);//边界SQL过滤表达式
            parameter.put("String_8", resultFilePath);//导出文件路径
            parameter.put("Double", size);//栅格分辨率
            parameter.put("Double_1", noDataValue);//空白区域值
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("resultLayerName", resultLayerName);
                jsonObject1.put("resultFilePath", resultFilePath);
                restResponse.setData(jsonObject1);
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    // tif发布超图服务工具--创建任务（导出tif文件）
    private RestResponse tifMapLayerToolJobPost7(String layerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:导出tif文件/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            String resultFilePath = filePath + layerName + ".tif";//导出文件路径
            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String_1", layerName);//数据集名称
            parameter.put("String_2", resultFilePath);//矢量数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("resultLayerName", layerName);
                jsonObject1.put("resultFilePath", resultFilePath);
                restResponse.setData(jsonObject1);
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    private RestResponse tifMapLayerToolJobPost8(String layerName, String timeStamp, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:dem高程计算汇水量a/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            String layerName2 = "temp_流向_" + timeStamp;
            String layerName3 = "temp_坡度_" + timeStamp;
            String layerName4 = "temp_地形_" + timeStamp;
            String layerName5 = "temp_汇水量_" + timeStamp;//结果数据集名

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//高程数据集名称
            parameter.put("String_1", layerName2);//流向栅格数据集名
            parameter.put("String_2", layerName3);//坡度数据集名称
            parameter.put("String_3", layerName4);//地形数据集名
            parameter.put("String_4", layerName5);//结果数据集名
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("pd", layerName3);
                jsonObject1.put("hsl", layerName5);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    private RestResponse tifMapLayerToolJobPost9(String layerName, String timeStamp, String serverToken, String sql, String flag) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:dem高程计算场地类别/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            String layerName2 = "temp_百分比_坡度_" + timeStamp;
            String layerName3 = "temp_场地类别_" + ("1".equals(flag) ? "活动构造区_" : "稳定大陆区_") + timeStamp;//结果数据集名

            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//高程数据集名称
            parameter.put("String_1", layerName2);//坡度数据集名称
            parameter.put("String_2", sql);//栅格计算表达式
            parameter.put("String_3", layerName3);//计算结果数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", layerName3);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    private RestResponse tifMapLayerToolJobPost10(String layerName, String timeStamp, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:重分类自然分割法发布/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            String layerName2 = "temp_重分类_自然分割_" + timeStamp;//结果数据集名
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//栅格数据集名称
            parameter.put("Integer", 5);//区域数量
            parameter.put("Integer_1", 0);//最低区域的值
            parameter.put("String_1", layerName2);//计算结果数据集名称
            parameter.put("String_2", mapsPath + "砂土液化层次分析法-图例.xml");//计算结果数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", layerName2);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    private RestResponse tifMapLayerToolJobPost11(String layerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:批量删除栅格数据集/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//栅格数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                restResponse.setMessage("删除成功！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    private RestResponse tifMapLayerToolJobPost12(String layerName, String resultLayerName1, String resultLayerName2,
                                                  String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:全部栅格值矢量化融合/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 栅格数据集名称；String_1  矢量化结果数据集名；String_2 结果数据集名
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//栅格数据集名称
            parameter.put("String_1", resultLayerName1);//矢量化结果数据集名
            parameter.put("String_2", resultLayerName2);//结果数据集名
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName2);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    private RestResponse tifMapLayerToolJobPost13(String layerName, String resultLayerName, String sql, String queryType, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg矢量过滤查询/jobs?token=" + serverToken;
            if (queryType.equals("fxfzypg")) {
//                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg矢量过滤查询/jobs?token=" + serverToken;
                //数据库端SQL查询语句
                sql = "select * from " + layerName + " where " + sql;
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg查询数据库fxfzypg/jobs?token=" + serverToken;
            } else if (queryType.equals("fxfzdzzh")) {
//                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg矢量过滤查询dzzh/jobs?token=" + serverToken;
                //数据库端SQL查询语句
                sql = "select * from " + layerName + " where " + sql;
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg查询数据库dzzh/jobs?token=" + serverToken;
            } else if (queryType.equals("datacenter")) {
//                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg矢量过滤查询基础数据/jobs?token=" + serverToken;
                //数据库端SQL查询语句
                sql = "select * from " + layerName + " where " + sql;
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg查询数据库基础数据/jobs?token=" + serverToken;
            } else if (queryType.equals("ypgTifCount")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:矢量过滤查询ypgcount/jobs?token=" + serverToken;
            }
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 矢量数据集名称，String_1 结果数据集名称，String_2 SQL查询表达式
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//矢量数据集名称
            parameter.put("String_1", resultLayerName);//结果数据集名称
            parameter.put("String_2", sql);//SQL查询表达式
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    private RestResponse tifMapLayerToolJobPost14(String layerName, String clipLayerName, String resultLayerName,
                                                  String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg矢量求交/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 源矢量数据集名，String_1 叠加数据集名，String_2 结果数据集名
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//源矢量数据集名
            parameter.put("String_1", clipLayerName);//叠加数据集名
            parameter.put("String_2", resultLayerName);//结果数据集名
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    //dem栅格计算ypg
    private RestResponse tifMapLayerToolJobPost15(String countString, String layerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:dem栅格计算ypg/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 算术表达式，String_1 栅格计算结果数据集名
            JSONObject parameter = new JSONObject();
            parameter.put("String", countString);//算术表达式
            parameter.put("String_1", layerName);//栅格计算结果数据集名
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", layerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    //栅格计算ypg
    private RestResponse tifMapLayerToolJobPost15_1(String countString, String layerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:栅格计算ypg/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 算术表达式，String_1 栅格计算结果数据集名
            JSONObject parameter = new JSONObject();
            parameter.put("String", countString);//算术表达式
            parameter.put("String_1", layerName);//栅格计算结果数据集名
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", layerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    //全部栅格矢量化发布图层模板
    private RestResponse tifMapLayerToolJobPost16(String layerName, String resultLayerName, String mapsName,
                                                  String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg全部栅格矢量化发布图层模板/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化结果数据集名，String_3 图层模板文件路径
            JSONObject parameter = new JSONObject();
            parameter.put("String_1", layerName);//栅格数据集名
            parameter.put("String_2", resultLayerName);//矢量化结果数据集名
            parameter.put("String_3", mapsPath + mapsName);//图层模板文件路径
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    //全部栅格矢量化
    private RestResponse tifMapLayerToolJobPost16_1(String layerName, String resultLayerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg全部栅格矢量化/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化结果数据集名，String_3 图层模板文件路径
            JSONObject parameter = new JSONObject();
            parameter.put("String_1", layerName);//栅格数据集名
            parameter.put("String_2", resultLayerName);//矢量化结果数据集名
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    //指定栅格矢量化缓冲区发布图层模板
    private RestResponse tifMapLayerToolJobPost17(String layerName, String resultLayerName, String resultLayerName2, String mapsName,
                                                  String gridvalue, String bufferMeter, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg指定栅格矢量化缓冲区4级发布图层模板/jobs?token=" + serverToken;
            if (gridvalue.equals("4")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg指定栅格矢量化缓冲区4级发布图层模板/jobs?token=" + serverToken;
            } else if (gridvalue.equals("5")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg指定栅格矢量化缓冲区5级发布图层模板/jobs?token=" + serverToken;
            }
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化数据集名，String_3 结果数据集名，String_4 图层模板文件路径，Long 指定栅格值，Double 缓冲区半径米
            JSONObject parameter = new JSONObject();
            parameter.put("String_1", layerName);//栅格数据集名
            parameter.put("String_2", resultLayerName);//矢量化数据集名
            parameter.put("String_3", resultLayerName2);//结果数据集名
            parameter.put("String_4", mapsPath + mapsName);//图层模板文件路径
//            parameter.put("Long", Integer.valueOf(gridvalue));//指定栅格值
            parameter.put("Double", Double.valueOf(bufferMeter));//缓冲区半径米
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName2);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    //指定栅格矢量化缓冲区
    private RestResponse tifMapLayerToolJobPost17_1(String layerName, String resultLayerName, String resultLayerName2,
                                                    String gridvalue, String bufferMeter, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg指定栅格矢量化缓冲区4级/jobs?token=" + serverToken;
            if (gridvalue.equals("4")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg指定栅格矢量化缓冲区4级/jobs?token=" + serverToken;
            } else if (gridvalue.equals("5")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg指定栅格矢量化缓冲区5级/jobs?token=" + serverToken;
            }
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化数据集名，String_3 结果数据集名，String_4 图层模板文件路径，Long 指定栅格值，Double 缓冲区半径米
            JSONObject parameter = new JSONObject();
            parameter.put("String_1", layerName);//栅格数据集名
            parameter.put("String_2", resultLayerName);//矢量化数据集名
            parameter.put("String_3", resultLayerName2);//结果数据集名
//            parameter.put("Long", Integer.valueOf(gridvalue));//指定栅格值
            parameter.put("Double", Double.valueOf(bufferMeter));//缓冲区半径米
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName2);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    private RestResponse tifMapLayerToolJobPost18(String layerName, String layerType, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:批量删除栅格数据集/jobs?token=" + serverToken;
            if (layerType.equals("栅格")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg批量删除栅格数据集/jobs?token=" + serverToken;
            } else if (layerType.equals("面")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg批量删除面数据集/jobs?token=" + serverToken;
            } else if (layerType.equals("shpcount")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:批量删除矢量数据集/jobs?token=" + serverToken;
            } else if (layerType.equals("demtif")) {
                dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:批量删除栅格数据集/jobs?token=" + serverToken;
            }

            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                restResponse.setMessage("删除成功！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    //ypg矢量裁剪发布图层模板
    private RestResponse tifMapLayerToolJobPost19(String layerName, String clipLayerName, String resultLayerName, String mapsName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg矢量裁剪发布图层模板/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化数据集名，String_3 结果数据集名，String_4 图层模板文件路径，Long 指定栅格值，Double 缓冲区半径米
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//矢量数据集名
            parameter.put("String_1", clipLayerName);//裁剪范围数据集
            parameter.put("String_2", resultLayerName);//结果数据集名
            parameter.put("String_3", mapsPath + mapsName);//图层模板文件路径
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    //ypg矢量裁剪发布图层模板复制
    private RestResponse tifMapLayerToolJobPost20(String layerName, String clipLayerName, String resultLayerName, String mapsName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg矢量裁剪发布图层模板复制/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化数据集名，String_3 结果数据集名，String_4 图层模板文件路径，Long 指定栅格值，Double 缓冲区半径米
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//矢量数据集名
            parameter.put("String_1", clipLayerName);//裁剪范围数据集
            parameter.put("String_2", resultLayerName);//结果数据集名
            parameter.put("String_3", mapsPath + mapsName);//图层模板文件路径
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    //ypg计算数据自动制图发布图层模板
    private RestResponse tifMapLayerToolJobPost21(String layerName, String mapsName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg计算数据自动制图发布图层模板/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化数据集名，String_3 结果数据集名，String_4 图层模板文件路径，Long 指定栅格值，Double 缓冲区半径米
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//结果数据集名称
            parameter.put("String_1", mapsPath + mapsName);//图层模板文件路径
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", layerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;

    }

    //demtif复制数据集到ypgTifCount
    private RestResponse tifMapLayerToolJobPost22(String layerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:dem复制数据集ypg/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化数据集名，String_3 结果数据集名，String_4 图层模板文件路径，Long 指定栅格值，Double 缓冲区半径米
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", layerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }

        return restResponse;
    }

    //ypgTifCount复制数据集到fxfzypg
    private RestResponse tifMapLayerToolJobPost23(String layerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg复制数据集/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化数据集名，String_3 结果数据集名，String_4 图层模板文件路径，Long 指定栅格值，Double 缓冲区半径米
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", layerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }

        return restResponse;
    }

    //矢量转换栅格ypg
    private RestResponse tifMapLayerToolJobPost24(String layerName, String clipLayerName, String fieldName, String resultLayerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:矢量转换栅格ypg/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化数据集名，String_3 结果数据集名，String_4 图层模板文件路径，Long 指定栅格值，Double 缓冲区半径米
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//矢量数据集名称
            parameter.put("String_1", clipLayerName);//边界矢量数据集名称
            parameter.put("String_2", fieldName);//字段名称
            parameter.put("String_3", resultLayerName);//结果数据集名称
            Double size = 0.0008880937137850466;//单元格大小，即栅格分辨率，可通过读取原栅格数据的分辨率设置，需要将如8.880937137850466E-4的科学记数转成浮点数
            Double noDataValue = -9999d;//空白区域值，即设置无值
            parameter.put("Double", size);//栅格分辨率
            parameter.put("Double_1", noDataValue);//空白区域值
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("resultLayerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }

        return restResponse;
    }

    //ypg矢量面裁剪栅格
    private RestResponse tifMapLayerToolJobPost25(String layerName, String clipLayerName, String resultLayerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg矢量面裁剪栅格/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化数据集名，String_3 结果数据集名，String_4 图层模板文件路径，Long 指定栅格值，Double 缓冲区半径米
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//栅格数据集名称
            parameter.put("String_1", clipLayerName);//边界矢量面数据集名称
            parameter.put("String_2", resultLayerName);//结果数据集名称
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }

        return restResponse;
    }

    //ypg矢量数据创建缓冲区
    private RestResponse tifMapLayerToolJobPost26(String layerName, String resultLayerName, String bufferMeter, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:ypg矢量数据创建缓冲区/jobs?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);
            JSONObject jsonObject = new JSONObject();
            //String 工作空间文件路径，String_1 栅格数据集名，String_2 矢量化数据集名，String_3 结果数据集名，String_4 图层模板文件路径，Long 指定栅格值，Double 缓冲区半径米
            JSONObject parameter = new JSONObject();
            parameter.put("String", layerName);//矢量数据集名称
            parameter.put("String_1", resultLayerName);//结果数据集名称
            parameter.put("Double", Double.valueOf(bufferMeter));//缓冲区半径米
            jsonObject.put("parameter", parameter);
            JSONArray environment = new JSONArray();
            jsonObject.put("environment", environment);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            // result.put("result", body.getString("jobID"));

            restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            if (restResponse.getCode() == 200) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("layerName", resultLayerName);
                restResponse.setData(jsonObject1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }

        return restResponse;
    }

    //栅格统计最大值最小值
    private RestResponse tifMapLayerToolJobGet1(String layerName, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:栅格基本统计/execute?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            // JSONObject jsonObject = new JSONObject();
            Map<String, Object> params = new HashMap<>();
            params.put("String", layerName);//计算结果数据集名称
            // jsonObject.put("parameter", parameter);
            // JSONArray environment = new JSONArray();
            // jsonObject.put("environment", environment);
            String parameter = JSON.toJSONString(params);
            dataUrl = dataUrl + "&parameter={parameter}&environment=" + new JSONArray();

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(new JSONObject(), headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<String> exchange = restTemplate.exchange(dataUrl, HttpMethod.GET, entity, String.class, parameter);
            JSONObject body = JSON.parseObject(JSON.parseObject(JSON.toJSONString(exchange)).getString("body"));
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            JSONObject jsonObject1 = JSON.parseObject(body.getString("basicstatistics-basicStatisticsAnalystResult"));
            if (jsonObject1 == null) {
                return RestResponse.fail("未获取到数据！");
            }
            JSONObject jsonObject2 = JSON.parseObject(jsonObject1.getString("basicStatisticsAnalystResult"));
            if (jsonObject2 == null) {
                return RestResponse.fail("未获取到数据！");
            }
            JSONObject jsonObject3 = new JSONObject();
            jsonObject3.put("max", jsonObject2.getBigDecimal("max"));
            jsonObject3.put("min", jsonObject2.getBigDecimal("min"));
            // restResponse = tifMapLayerToolJobGet(body.getString("jobID"), serverToken);
            // if (restResponse.getCode()==200){
            //     restResponse.setData(filePath4 + layerName + ".tif");
            // }
            restResponse = RestResponse.succeed(jsonObject3);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //矢量查询计算面积（平方千米）
    private RestResponse tifMapLayerToolJobGet2(String layerName, String sqlFilter, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/sps.WorkflowProcessFactory.models.tif发布:矢量查询计算面积ypg/execute?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            //执行处理自动化工具时的参数设置，形式为{”ParameterID1”:”value1”,”ParameterID2”:”value2”,……}，其中ParameterID为工具的参数ID，由对应的处理自动化工具描述可以确定，value为参数的值
            // JSONObject jsonObject = new JSONObject();
            Map<String, Object> params = new HashMap<>();
            params.put("String", layerName);//矢量数据集名称
            params.put("String_1", sqlFilter);//查询过滤表达式
            // jsonObject.put("parameter", parameter);
            // JSONArray environment = new JSONArray();
            // jsonObject.put("environment", environment);
            String parameter = JSON.toJSONString(params);
            dataUrl = dataUrl + "&parameter={parameter}&environment=" + new JSONArray();

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(new JSONObject(), headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<String> exchange = restTemplate.exchange(dataUrl, HttpMethod.GET, entity, String.class, parameter);
            JSONObject body = JSON.parseObject(JSON.parseObject(JSON.toJSONString(exchange)).getString("body"));
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            //面积
            String area = body.getString("computegeodesicarea-totalArea");
            restResponse = RestResponse.succeed(area);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    private RestResponse tifMapLayerToolJobGet(String jobID, String serverToken) {
        JSONObject result = new JSONObject();
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/jobs/" + jobID + ".json?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(new JSONObject(), headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.GET, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            /*if(body.containsKey("error")){
                return RestResponse.fail("未获取到数据！");
            }*/
            if (!body.getJSONObject("state").getBooleanValue("success")
                    && !body.getJSONObject("state").getString("runState").equals("RUNNING")) {
                return RestResponse.fail("未获取到数据！");
            }
            BigDecimal percent = body.getJSONObject("progress").getBigDecimal("percent");
            while (percent.compareTo(BigDecimal.valueOf(100)) < 0) {
                Thread.sleep(1000);
                //获取任务执行百分比
                percent = tifMapLayerToolJobGetPercent(jobID, serverToken);
                if (percent.compareTo(BigDecimal.valueOf(-1)) == 0) {
                    return RestResponse.fail("该任务未获取到数据！");
                }
            }
            result.put("result", "获取成功！");
        } catch (Exception e) {
            e.printStackTrace();
            if (e.getMessage().contains("无效的令牌")) {
                return RestResponse.fail("无效的令牌！");
            }
            return tifMapLayerToolJobGet(jobID, serverToken);
        }
        return RestResponse.succeed(result);
    }

    //获取任务执行百分比
    private BigDecimal tifMapLayerToolJobGetPercent(String jobID, String serverToken) {
        BigDecimal jobPercent = BigDecimal.ZERO;
        try {
            String dataUrl = iServerHttp + "/iserver/services/geoprocessing/restjsr/gp/v2/jobs/" + jobID + ".json?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return jobPercent;
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(new JSONObject(), headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.GET, entity, JSONObject.class);
            JSONObject body = exchange.getBody();
            if (body == null) {
                return jobPercent;
            }
            /*if(body.containsKey("error")){
                return BigDecimal.valueOf(-1);
            }*/
            if (!body.getJSONObject("state").getBooleanValue("success")
                    && !body.getJSONObject("state").getString("runState").equals("RUNNING")) {
                return BigDecimal.valueOf(-1);
            }
            BigDecimal percent = body.getJSONObject("progress").getBigDecimal("percent");
            if (percent.compareTo(BigDecimal.valueOf(100)) == 0) {
                if (body.getJSONObject("state").getString("runState").equals("RUNNING")) {//正在执行
                    percent = BigDecimal.valueOf(99);
                }
            }
            jobPercent = percent;
        } catch (Exception e) {
            e.printStackTrace();
            if (e.getMessage().contains("无效的令牌")) {
                return BigDecimal.valueOf(-1);
            }
            return jobPercent;
        }
        return jobPercent;
    }

    //获取Web打印出图模板列表
    @Override
    public List<TemplateEntity> getWebprintingLayoutsList() {
        List<TemplateEntity> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("type", "getWebprintingLayoutsList");
        RestResponse res = getServerToken(map);//获取Web打印出图模板列表
        if (res.getCode() == 200) {
            list = (List<TemplateEntity>) res.getData();
        }
        return list;
    }

    //获取Web打印出图模板列表
    private RestResponse supermapGetTemplateEntityList(Map<String, Object> map, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/services/webprinting/rest/webprinting/v1/layouts.rjson?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //System.out.println(dataUrl);

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(new JSONObject(), headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<String> exchange = restTemplate.exchange(dataUrl, HttpMethod.GET, entity, String.class);
            JSONArray body = JSON.parseArray(JSON.parseObject(JSON.toJSONString(exchange)).getString("body"));
            if (body == null) {
                return null;
            }
            if (body.size() > 0) {
                List<TemplateEntity> templateEntityList = new ArrayList<>();
                for (int i = 0; i < body.size(); i++) {
                    String templateName = body.getJSONObject(i).getString("templateName");
                    Integer webMapFrameSizeX = body.getJSONObject(i).getJSONArray("webMapFrameSize").getInteger(0);
                    Integer webMapFrameSizeY = body.getJSONObject(i).getJSONArray("webMapFrameSize").getInteger(1);
                    TemplateEntity templateEntity = new TemplateEntity();
                    templateEntity.setTemplateName(templateName);
                    templateEntity.setWebMapFrameSizeX(webMapFrameSizeX);
                    templateEntity.setWebMapFrameSizeY(webMapFrameSizeY);
                    templateEntityList.add(templateEntity);
                }
                restResponse = RestResponse.succeed(templateEntityList);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //上传模板文件到超图模板目录
    @Override
    public RestResponse uploadTemplateFile(String attachId, String format) {
        Map<String, Object> map = new HashMap<>();
        map.put("type", "uploadTemplateFile");
        String srcFile = null;
        //根据id和文件名获取真实的放在磁盘上的文件
        AttachmentInfoEntity attachmentInfoEntity = attachmentInfoService.getAttach(attachId);
        String attachPath = attachmentInfoEntity.getAttachPath();
        if (attachPath.endsWith(".ult")) {
            srcFile = attachmentInfoEntity.getFileDirId() + attachPath;
        }
        map.put("srcFile", srcFile);
        map.put("format", format);
        RestResponse res = getServerToken(map);//获取Web打印出图模板列表
        return res;
    }

    //上传模板文件到超图模板目录
    private RestResponse supermapPostTemplateFile(Map<String, Object> map, String format, String serverToken) {
        RestResponse restResponse = null;
        try {
            //欲上传的源文件路径
            String srcFile = (String) map.get("srcFile");
//            srcFile = "D:/template/Administrative_Active_Fault-h1012/Administrative_Active_Fault-h1012_1710223152950.ult";
            if (PlatformObjectUtils.isEmpty(srcFile)) {
                System.out.println("无上传的源文件路径");
                return RestResponse.fail("无上传的源文件路径！");
            }
            File zipFile = null;
            if (srcFile.endsWith(".ult")) {
                String originFile = srcFile;
                String timeStamp = System.currentTimeMillis() + "";//时间戳，防止重名
                String tempFormat = "fxfzypg-hf_";
                if (format.equals("0")) {//横版
                    tempFormat = "fxfzypg-hf_";
                } else if (format.equals("1")) {//竖版
                    tempFormat = "fxfzypg-v_";
                } else if (format.equals("3")) {//横版带简介
                    tempFormat = "fxfzypg-h_";
                }
                srcFile = srcFile.substring(0, srcFile.lastIndexOf(File.separator)) + "/" + tempFormat + timeStamp + ".ult";
                //复制文件，设置文件名，防止原文件名称超长
                FileUtil.copy(originFile, srcFile, true);
                //将.ult模板文件打包压缩包.zip
                //获取复制的文件
                File ultFile = new File(srcFile);
                //压缩文件路径
                srcFile = srcFile.substring(0, srcFile.lastIndexOf(".")) + ".zip";
                // 打成压缩包
                zipFile = new File(srcFile);
                FileOutputStream zipFos = new FileOutputStream(zipFile);
                ArchiveOutputStream archOut = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, zipFos);
                if (archOut instanceof ZipArchiveOutputStream) {
                    ZipArchiveOutputStream zos = (ZipArchiveOutputStream) archOut;
                    ZipArchiveEntry zipEntry = new ZipArchiveEntry(ultFile, ultFile.getName());
                    zos.putArchiveEntry(zipEntry);
                    zos.write(FileUtils.readFileToByteArray(ultFile));
                    zos.closeArchiveEntry();
                    zos.flush();
                    zos.close();
                }
                // 删除复制的文件
                if (ultFile.exists()) {
                    ultFile.delete();
                }
            } else {
                System.out.println("源文件不是超图Web打印模板");
                return RestResponse.fail("源文件不是超图Web打印模板！");
            }
//            String srcFile = "C:/Users/lenovo/Desktop/新建文件夹/fxfzaqbz-hf_1699350083999.zip";
            String fileName = srcFile.substring(srcFile.lastIndexOf("/") + 1);
            //欲上传的目标位置（位于服务器，相对于iServer应用目录/webapps/iserver/）
//            String destFile = "C:/Users/lenovo/Desktop/192/supermap-iserver-1111-22428-6922-windows-x64-deploy-usv3236/supermap-iserver-1111-22428-6922-windows-x64-deploy/webapps/iserver/templates/webprinting-layouts/fxfzaqbz-hf_1699350083888.zip";
//            String destFile = "/templates/webprinting-layouts/"+fileName;//相对路径
//            String destFile = "/usr/supermaprootnew/iserver/webapps/iserver/templates/webprinting-layouts/"+fileName;//绝对路径
//            String destFile = "/usr/supermaproot-111a/supermap-iserver-11.1.1a-linux-x64/supermap-iserver-11.1.1a-linux-x64/webapps/iserver/templates/webprinting-layouts/"+fileName;//绝对路径
//            String destFile = "/usr/supermaproot-333a/supermap-iserver-1111-23101-7024-linux-x64-deploy/webapps/iserver/templates/webprinting-layouts/";//绝对路径
            //查询字典--超图数据源工作空间文件路径
            DictItemEntity dte = dictItemRepository.findOneByDictItemCodeAndDictId("webprinting", "12");
            String destFile = dte.getDictItemName();//工作空间文件路径
            destFile += fileName;
            System.out.println(destFile);
            //是否覆盖
            boolean overwrite = true;
            //是否解压，上传的是zip文件，且unzip为true时，上传后iServer会将zip文件解压
            boolean unzip = true;

            String dataUrl = iServerHttp + "/iserver/manager/filemanager/uploadtasks.rjson?token=" + serverToken;
            dataUrl += "&toFile=" + destFile + "&overwrite=" + overwrite + "&unzip=" + unzip;

            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");

            //获取文件
            File file = new File(srcFile);
            if (!file.isFile()) {
                System.out.println("欲上传的源文件不存在。");
                return RestResponse.fail("欲上传的源文件不存在！");
            }
            //通过uploadtasks资源，创建一个uploadtask资源用于文件上传，并返回uploadtask资源的URL
            //创建时传入源文件的大小、目标路径、MD5，服务器端可据此判断磁盘空间是否充足，并在上传完成后进行MD5校验。
            long srcFileSize = file.length();
            String md5 = getMD5(file);
            String uploadtaskurl = getUploadTaskURL(dataUrl, srcFileSize, destFile, md5, serverToken);
            System.out.println("上传模板文件任务--" + uploadtaskurl);
            if (PlatformObjectUtils.isNotEmpty(uploadtaskurl)) {
                uploadtaskurl += ".json";
                uploadtaskurl = uploadtaskurl + "?toFile=" + destFile + "&overwrite=" + overwrite + "&unzip=" + unzip + "&token=" + serverToken;
                MultiValueMap<String, Object> bodyMap = new LinkedMultiValueMap<>();
                bodyMap.add("file", new FileSystemResource(file));
                HttpHeaders headers = new HttpHeaders();
                headers.setContentType(MediaType.MULTIPART_FORM_DATA);
                HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(bodyMap, headers);
                RestTemplate restTemplate = new RestTemplate();
                ResponseEntity<String> response = restTemplate.exchange(uploadtaskurl, HttpMethod.POST, requestEntity, String.class);
                JSONObject body = JSON.parseObject(JSON.parseObject(JSON.toJSONString(response)).getString("body"));
                System.out.println(body);
                String resultFileName = body.getString("fileName");//	上传文件或目录的名称。
//                String resultFilePath = body.getString("filePath");//文件上传后的目标文件或目录，用相对路径表示。相对路径的起算目录为 iServer 应用目录，如 Package 包中为%SuperMap iServer_HOME%\webapp\ iserver 目录 。
//                String fileSize = body.getString("fileSize");//	上传文件的大小，单位为字节。
//                String isDirectory = body.getString("isDirectory");//是否是目录，默认为 false。
                System.out.println("上传模板文件到超图模板目录成功" + resultFileName);
                // 删除压缩包
                if (zipFile.exists()) {
                    zipFile.delete();
                }
                /*//判断模板是否已在超图Web打印模板列表中
                boolean bool = false;
                while(bool==false){
                    Thread.sleep(10000);//10秒
                    //获取Web打印出图模板列表
                    List<TemplateEntity> templateEntityList = getWebprintingLayoutsList();
                    if(templateEntityList.size()>0){
                        for(TemplateEntity entity : templateEntityList){
                            if(resultFileName.equals(entity.getTemplateName())){
                                bool = true;
                                break;
                            }
                        }
                    }
                }
                System.out.println("成功发布模板文件到超图模板目录"+resultFileName);*/
                return RestResponse.succeed(resultFileName);
            } else {
                return RestResponse.fail("上传失败");
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
    }

    //计算 file的MD5码
    private static String getMD5(File file) {
        String result = "";
        try {
            byte[] filebytes = FileUtils.readFileToByteArray(file);
            final char[] hexDigits = "0123456789abcdef".toCharArray();
            final byte[] md5 = MessageDigest.getInstance("MD5").digest(filebytes);
            final char[] md5Chars = new char[32];
            int i = 0;
            for (final byte b : md5) {
                md5Chars[i++] = hexDigits[(b >> 4) & 0xF];
                md5Chars[i++] = hexDigits[b & 0xF];
            }
            result = new String(md5Chars);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException nsae) {
            throw new IllegalStateException("No MD5 algorithm, unable to compute MD5");
        }
        return result;
    }

    //通过uploadtasks资源，创建一个uploadtask资源用于文件上传，并返回uploadtask资源的URL
    //创建时传入源文件的大小、目标路径、MD5，服务器端可据此判断磁盘空间是否充足，并在上传完成后进行MD5校验。
    public String getUploadTaskURL(String uploadtasksurl, long srcfileSize, String destFile, String md5, String token) throws ClientProtocolException, IOException {
        String result = "";
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(uploadtasksurl + "?token=" + token);
        //创建时传入源文件的大小、目标路径、MD5，服务器端可据此判断磁盘空间是否充足，并在上传完成后进行MD5校验。
        JSONObject entityStr = new JSONObject();
        try {
            entityStr.put("fileSize", srcfileSize);
            entityStr.put("filePath", destFile);
//            entityStr.put("path", destFile);
            entityStr.put("md5", md5);
        } catch (JSONException e1) {
            e1.printStackTrace();
        }
        StringEntity entity = new StringEntity(entityStr.toString(), "utf-8");
        entity.setContentType(new BasicHeader(org.apache.http.protocol.HTTP.CONTENT_TYPE, "application/json"));
        post.setEntity(entity);

        org.apache.http.HttpResponse response = client.execute(post);
        org.apache.http.HttpEntity responseEntity = response.getEntity();
        InputStream is = responseEntity.getContent();
        String responseEntityStr = new String(IOUtils.toByteArray(is), "utf-8");
        try {
            JSONObject body = JSON.parseObject(responseEntityStr);
            result = body.getString("newResourceLocation");
            System.out.println(result);
        } catch (JSONException e) {
            e.printStackTrace();
            result = null;
        }
        return result;
    }

    //刷新指定超图工作空间数据源数据集
    private RestResponse mapLayerWorkspaceReload(String smwuUrl, String datasource, String dataset, String serverToken) {
        RestResponse restResponse = null;
        try {
            String dataUrl = iServerHttp + "/iserver/manager/workspaces/workspacereload.rjson?token=" + serverToken;
            try {
                dataUrl = URLDecoder.decode(dataUrl, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return RestResponse.fail(e.getMessage());
            }
            dataUrl = dataUrl.replaceAll("%3A", ":").replaceAll("%2F", "/").replaceAll("\\+", "%20");
            //刷新指定数据源数据集时的参数设置，形式为{"workspaceConnectionInfo":"E:/MapData/fxfzdzzh/fxfzdzzh10/fxfzdzzh.smwu","isForce":true,"datasets":{"fxfzdzzh":["dzzh_slide_result_intensity"]}}
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("workspaceConnectionInfo", smwuUrl);
            jsonObject.put("isForce", true);
            //有数据集名则刷新指定数据集，无数据集名则刷新整个数据源
            if (PlatformObjectUtils.isNotEmpty(dataset)) {
                JSONObject datasets = new JSONObject();
                JSONArray datasetArray = new JSONArray();
                datasetArray.add(dataset);
                datasets.put(datasource, datasetArray);//数据源数据集名称
                jsonObject.put("datasets", datasets);
            }

            HttpHeaders headers = new HttpHeaders();
            headers.set("Content-Type", "application/json; charset=UTF-8");

            HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObject, headers);
//            RestTemplate restTemplate = getRestTemplate();
            ResponseEntity<String> exchange1 = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, String.class);
//            ResponseEntity<JSONObject> exchange = restTemplate.exchange(dataUrl, HttpMethod.POST, entity, JSONObject.class);
            JSONObject body = JSON.parseObject(exchange1.getBody());
            if (body == null) {
                return RestResponse.fail("未获取到数据！");
            }
            if (body.getBooleanValue("succeed")) {
                restResponse = RestResponse.succeed("刷新成功");
            } else {
                restResponse = RestResponse.fail("刷新失败");
            }

        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail(e.getMessage());
        }
        return restResponse;
    }

    //刷新指定超图工作空间数据源数据集
    @Override
    public boolean getWorkspaceReload(String dataset) {
        StringBuilder datasource = new StringBuilder("fxfzypg");
        String[] activeProfiles = environment.getActiveProfiles();
        for (String profile : activeProfiles) {
            if("guojia".equals(profile)){
                datasource.append("_country");
                break;
            }
        }
        boolean bool = false;
        Map<String, Object> map = new HashMap<>();
        map.put("type", "WorkspaceReload");
        map.put("datasource", datasource);//数据源（数据库名）
        map.put("dataset", dataset);//数据集（表名）
        RestResponse restResponse1 = getServerToken(map);//刷新指定超图工作空间数据源数据集
        if (restResponse1.getCode() == 200) {
            //刷新成功
            bool = true;
        }

        return bool;
    }

    //刷新指定超图工作空间数据源数据集
    @Override
    public boolean getWorkspaceReload(String datasource, String dataset) {
        boolean bool = false;
        Map<String, Object> map = new HashMap<>();
        map.put("type", "WorkspaceReload");
        map.put("datasource", datasource);//数据源（数据库名）
        map.put("dataset", dataset);//数据集（表名）
        RestResponse restResponse1 = getServerToken(map);//刷新指定超图工作空间数据源数据集
        if (restResponse1.getCode() == 200) {
            //刷新成功
            bool = true;
        }

        return bool;
    }

    //获取超图服务token
    @Override
    public String getToken() {
        Map<String, Object> map = new HashMap<>();
        map.put("type", "token");
        RestResponse restResponse = getServerToken(map);
        String token = (String) restResponse.getData();

        return token;
    }

    //根据名称、类型批量删除数据集
    @Override
    public boolean batchDelByLayerType(String layerName, String layerType) {
        boolean bool = false;
        Map<String, Object> map = new HashMap<>();
        map.put("type", "batchDelByLayerType");
        map.put("layerName", layerName);//数据集（表名）
        map.put("layerType", layerType);//数据类型（栅格、面）
        RestResponse restResponse1 = getServerToken(map);//根据名称、类型批量删除数据集
        if (restResponse1.getCode() == 200) {
            //删除成功
            bool = true;
        }

        return bool;
    }

    //清除超图工作空间临时数据集
    @Override
    public void deleteWorkspaceDatasetTemp() {
        batchDelByLayerType("temp_*", "面");
        batchDelByLayerType("ypg逻辑斯蒂模型_分级计算_*", "栅格");
        batchDelByLayerType("temp_*", "shpcount");
        batchDelByLayerType("temp_*", "demtif");
        batchDelByLayerType("jc_stratum_lithology_矢量转栅格_*", "demtif");
        batchDelByLayerType("dzzh_sys_landform_矢量转栅格_*", "demtif");
        batchDelByLayerType("ypg_jc_climate_矢量转栅格_*", "demtif");
        batchDelByLayerType("dzzh_sys_natural_density_矢量转栅格_*", "demtif");
    }
}
